package com.fzzz.kotlindemo;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by Shen Chao
 * Created by 2018-12-14
 */
public class SecondActivity1 extends AppCompatActivity {

    private EditText etInput;
    private Button btn;
    private TextView tvContent;
    private Button btnClose;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        etInput = findViewById(R.id.et_input);
        btn = findViewById(R.id.btn);
        tvContent = findViewById(R.id.tv_content);
        btnClose = findViewById(R.id.btn_close);
        //new 对象传进去
        tvContent.setTransformationMethod(new AllCapTransformationMethod());

        //空安全变量
        String btnString = "确认";
        String contentString = "输出内容";
        //可为空字符串变量
        String inputHint = null;
        inputHint = "输入数字";

        etInput.setHint(inputHint);
        btn.setText(btnString);
        tvContent.setText(contentString);

        User user = getIntent().getParcelableExtra("user");
        tvContent.setText(user.getName() + "-----" + user.getAge());

        btnClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setResult(Activity.RESULT_OK, getIntent());
                finish();
            }
        });

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String x = etInput.getText().toString().trim();
                Toast.makeText(SecondActivity1.this, x, Toast.LENGTH_SHORT).show();
            }
        });
    }
}
